﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using PoolGame2.Assets;
using PoolGame2.Physics;
using PoolGame2.Menus;
using PoolGame2.Player;
using PoolGame2.Networking;
using PoolGame2.Managers;
using PoolGame2.Controls;
using PoolGame2.Game;

namespace PoolGame2.Rules
{
    class BallCRules : RuleC
    {
        PoolGame Game;

        public BallCRules(PoolGame game)
        {
            this.Game = game;
        }

        public override RulesEnum CheckRules(Ball ball)
        {

            if (ball.getNumber() == 0 && ball.getPocketed())
            {
                // Cue ball's gone into the pocket
                // TODO: If black's already sunk, game over
                ball.endPocket = null;
                return RulesEnum.POT_CUE;
            }


            return RulesEnum.ERROR;
        }
        public override RulesEnum CheckRules(Ball cball, Ball ball)
        {
            PlayerPresence playerPres = Game.gameManager.GetPlayerPresence();
            if (cball.getNumber() == 0 && (playerPres.getColours() || playerPres.getStripes()))
            { // Definitely hitting cueball
                if (playerPres.getStripes() && ball.getNumber() > 8)
                {
                    //Legal shot - is stripes, hit stripes
                    return RulesEnum.SHOT_VALID;
                }
                else if (playerPres.getColours() && ball.getNumber() < 8)
                {
                    //Legal shot - is colours, hit colours
                    return RulesEnum.SHOT_VALID;
                }
                else
                {
                    //Illegal shot - any other combination
                    return RulesEnum.SHOT_INVALID;
                }
            }else if (cball.getNumber() == 0 && (!playerPres.getColours() && !playerPres.getStripes())){
                // If we haven't yet got a colour, just don't hit the black
                if (ball.getNumber() == 8){
                    // Hit the black anyway...
                    return RulesEnum.SHOT_INVALID;
                }else{
                    // Didn't hit the black, sorted
                    return RulesEnum.SHOT_VALID;
                }
            }
            return RulesEnum.ERROR;
        }
    }
}
